home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / protocols / interfaces.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  11KB  |  368 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import generators
  5. __all__ = [
  6.     'Protocol',
  7.     'InterfaceClass',
  8.     'Interface',
  9.     'AbstractBase',
  10.     'AbstractBaseMeta',
  11.     'IAdapterFactory',
  12.     'IProtocol',
  13.     'IAdaptingProtocol',
  14.     'IOpenProtocol',
  15.     'IOpenProvider',
  16.     'IOpenImplementor',
  17.     'IImplicationListener',
  18.     'Attribute',
  19.     'Variation']
  20. import api
  21. from advice import metamethod, classicMRO, mkRef
  22. from adapters import composeAdapters, updateWithSimplestAdapter
  23. from adapters import NO_ADAPTER_NEEDED, DOES_NOT_SUPPORT
  24. from types import InstanceType
  25.  
  26. try:
  27.     from thread import allocate_lock
  28. except ImportError:
  29.     
  30.     try:
  31.         from dummy_thread import allocate_lock
  32.     except ImportError:
  33.         
  34.         class allocate_lock(object):
  35.             __slots__ = ()
  36.             
  37.             def acquire(*args):
  38.                 pass
  39.  
  40.             
  41.             def release(*args):
  42.                 pass
  43.  
  44.  
  45.     except:
  46.         None<EXCEPTION MATCH>ImportError
  47.     
  48.  
  49.     None<EXCEPTION MATCH>ImportError
  50.  
  51.  
  52. class Protocol:
  53.     
  54.     def __init__(self):
  55.         self._Protocol__adapters = { }
  56.         self._Protocol__implies = { }
  57.         self._Protocol__listeners = None
  58.         self._Protocol__lock = allocate_lock()
  59.  
  60.     
  61.     def getImpliedProtocols(self):
  62.         out = []
  63.         add = out.append
  64.         self._Protocol__lock.acquire()
  65.         
  66.         try:
  67.             for k, v in self._Protocol__implies.items():
  68.                 proto = k()
  69.                 if proto is None:
  70.                     del self._Protocol__implies[k]
  71.                     continue
  72.                 add((proto, v))
  73.             
  74.             return out
  75.         finally:
  76.             self._Protocol__lock.release()
  77.  
  78.  
  79.     
  80.     def addImpliedProtocol(self, proto, adapter = NO_ADAPTER_NEEDED, depth = 1):
  81.         self._Protocol__lock.acquire()
  82.         
  83.         try:
  84.             key = mkRef(proto)
  85.             if not updateWithSimplestAdapter(self._Protocol__implies, key, adapter, depth):
  86.                 return self._Protocol__implies[key][0]
  87.         finally:
  88.             self._Protocol__lock.release()
  89.  
  90.         for baseAdapter, d in self._Protocol__adapters.items():
  91.             api.declareAdapterForType(proto, composeAdapters(baseAdapter, self, adapter), klass, depth + d)
  92.         
  93.         if self._Protocol__listeners:
  94.             for listener in self._Protocol__listeners.keys():
  95.                 listener.newProtocolImplied(self, proto, adapter, depth)
  96.             
  97.         
  98.         return adapter
  99.  
  100.     addImpliedProtocol = metamethod(addImpliedProtocol)
  101.     
  102.     def registerImplementation(self, klass, adapter = NO_ADAPTER_NEEDED, depth = 1):
  103.         self._Protocol__lock.acquire()
  104.         
  105.         try:
  106.             if not updateWithSimplestAdapter(self._Protocol__adapters, klass, adapter, depth):
  107.                 return self._Protocol__adapters[klass][0]
  108.         finally:
  109.             self._Protocol__lock.release()
  110.  
  111.         if adapter is DOES_NOT_SUPPORT:
  112.             return adapter
  113.         
  114.         for extender, d in self.getImpliedProtocols():
  115.             api.declareAdapterForType(proto, composeAdapters(adapter, self, extender), klass, depth + d)
  116.         
  117.         return adapter
  118.  
  119.     registerImplementation = metamethod(registerImplementation)
  120.     
  121.     def registerObject(self, ob, adapter = NO_ADAPTER_NEEDED, depth = 1):
  122.         if api.adapt(ob, IOpenProvider).declareProvides(self, adapter, depth):
  123.             if adapter is DOES_NOT_SUPPORT:
  124.                 return None
  125.             
  126.             for extender, d in self.getImpliedProtocols():
  127.                 api.declareAdapterForObject(proto, composeAdapters(adapter, self, extender), ob, depth + d)
  128.             
  129.         
  130.  
  131.     registerObject = metamethod(registerObject)
  132.     
  133.     def __adapt__(self, obj):
  134.         get = self._Protocol__adapters.get
  135.         
  136.         try:
  137.             typ = obj.__class__
  138.         except AttributeError:
  139.             typ = type(obj)
  140.  
  141.         
  142.         try:
  143.             mro = typ.__mro__
  144.         except AttributeError:
  145.             mro = classicMRO(typ, extendedClassic = True)
  146.  
  147.         for klass in mro:
  148.             factory = get(klass)
  149.             if factory is not None:
  150.                 return factory[0](obj)
  151.                 continue
  152.         
  153.  
  154.     
  155.     try:
  156.         from _speedups import Protocol__adapt__ as __adapt__
  157.     except ImportError:
  158.         pass
  159.  
  160.     __adapt__ = metamethod(__adapt__)
  161.     
  162.     def addImplicationListener(self, listener):
  163.         self._Protocol__lock.acquire()
  164.         
  165.         try:
  166.             if self._Protocol__listeners is None:
  167.                 WeakKeyDictionary = WeakKeyDictionary
  168.                 import weakref
  169.                 self._Protocol__listeners = WeakKeyDictionary()
  170.             
  171.             self._Protocol__listeners[listener] = 1
  172.         finally:
  173.             self._Protocol__lock.release()
  174.  
  175.  
  176.     addImplicationListener = metamethod(addImplicationListener)
  177.     
  178.     def __call__(self, ob, default = api._marker):
  179.         return api.adapt(ob, self, default)
  180.  
  181.  
  182.  
  183. try:
  184.     from _speedups import Protocol__call__
  185. except ImportError:
  186.     pass
  187.  
  188. from new import instancemethod
  189. Protocol.__call__ = instancemethod(Protocol__call__, None, Protocol)
  190.  
  191. class AbstractBaseMeta(Protocol, type):
  192.     
  193.     def __init__(self, __name__, __bases__, __dict__):
  194.         type.__init__(self, __name__, __bases__, __dict__)
  195.         Protocol.__init__(self)
  196.         for b in __bases__:
  197.             if isinstance(b, AbstractBaseMeta) and b.__bases__ != (object,):
  198.                 self.addImpliedProtocol(b)
  199.                 continue
  200.         
  201.  
  202.     
  203.     def __setattr__(self, attr, val):
  204.         if attr == '__bases__':
  205.             raise TypeError("Can't change interface __bases__", self)
  206.         
  207.         type.__setattr__(self, attr, val)
  208.  
  209.     __call__ = type.__call__
  210.  
  211.  
  212. class AbstractBase(object):
  213.     __metaclass__ = AbstractBaseMeta
  214.  
  215.  
  216. class InterfaceClass(AbstractBaseMeta):
  217.     
  218.     def __call__(self, *_InterfaceClass__args, **_InterfaceClass__kw):
  219.         if self.__init__ is Interface.__init__:
  220.             return Protocol.__call__(self, *_InterfaceClass__args, **_InterfaceClass__kw)
  221.         else:
  222.             return type.__call__(self, *_InterfaceClass__args, **_InterfaceClass__kw)
  223.  
  224.     
  225.     def getBases(self):
  226.         return _[1]
  227.  
  228.  
  229.  
  230. class Interface(object):
  231.     __metaclass__ = InterfaceClass
  232.  
  233.  
  234. class Variation(Protocol):
  235.     
  236.     def __init__(self, baseProtocol, context = None):
  237.         self.baseProtocol = baseProtocol
  238.         self.context = context
  239.         Protocol.__init__(self)
  240.         api.declareAdapterForProtocol(self, NO_ADAPTER_NEEDED, baseProtocol)
  241.  
  242.     
  243.     def __repr__(self):
  244.         if self.context is None:
  245.             return 'Variation(%r)' % self.baseProtocol
  246.         
  247.         return 'Variation(%r,%r)' % (self.baseProtocol, self.context)
  248.  
  249.  
  250.  
  251. class Attribute(object):
  252.     
  253.     def __init__(self, doc, name = None, value = None):
  254.         self.__doc__ = doc
  255.         self.name = name
  256.         self.value = value
  257.  
  258.     
  259.     def __get__(self, ob, typ = None):
  260.         if ob is None:
  261.             return self
  262.         
  263.         if not self.name:
  264.             raise NotImplementedError('Abstract attribute')
  265.         
  266.         
  267.         try:
  268.             return ob.__dict__[self.name]
  269.         except KeyError:
  270.             return self.value
  271.  
  272.  
  273.     
  274.     def __set__(self, ob, val):
  275.         if not self.name:
  276.             raise NotImplementedError('Abstract attribute')
  277.         
  278.         ob.__dict__[self.name] = val
  279.  
  280.     
  281.     def __delete__(self, ob):
  282.         if not self.name:
  283.             raise NotImplementedError('Abstract attribute')
  284.         
  285.         del ob.__dict__[self.name]
  286.  
  287.     
  288.     def __repr__(self):
  289.         return 'Attribute: %s' % self.__doc__
  290.  
  291.  
  292.  
  293. class IAdapterFactory(Interface):
  294.     
  295.     def __call__(ob):
  296.         pass
  297.  
  298.  
  299.  
  300. class IProtocol(Interface):
  301.     
  302.     def __hash__():
  303.         pass
  304.  
  305.     
  306.     def __eq__(other):
  307.         pass
  308.  
  309.     
  310.     def __ne__(other):
  311.         pass
  312.  
  313.  
  314.  
  315. class IAdaptingProtocol(IProtocol):
  316.     
  317.     def __adapt__(ob):
  318.         pass
  319.  
  320.  
  321.  
  322. class IConformingObject(Interface):
  323.     
  324.     def __conform__(protocol):
  325.         pass
  326.  
  327.  
  328.  
  329. class IOpenProvider(Interface):
  330.     
  331.     def declareProvides(protocol, adapter = NO_ADAPTER_NEEDED, depth = 1):
  332.         pass
  333.  
  334.  
  335.  
  336. class IOpenImplementor(Interface):
  337.     
  338.     def declareClassImplements(protocol, adapter = NO_ADAPTER_NEEDED, depth = 1):
  339.         pass
  340.  
  341.  
  342.  
  343. class IOpenProtocol(IAdaptingProtocol):
  344.     
  345.     def addImpliedProtocol(proto, adapter = NO_ADAPTER_NEEDED, depth = 1):
  346.         pass
  347.  
  348.     
  349.     def registerImplementation(klass, adapter = NO_ADAPTER_NEEDED, depth = 1):
  350.         pass
  351.  
  352.     
  353.     def registerObject(ob, adapter = NO_ADAPTER_NEEDED, depth = 1):
  354.         pass
  355.  
  356.     
  357.     def addImplicationListener(listener):
  358.         pass
  359.  
  360.  
  361.  
  362. class IImplicationListener(Interface):
  363.     
  364.     def newProtocolImplied(srcProto, destProto, adapter, depth):
  365.         pass
  366.  
  367.  
  368.